/**
 * 
 */
package com.alkandros.linesmash.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.alkandros.linesmash.R;
import com.alkandros.linesmash.constants.AppConstants;
import com.alkandros.linesmash.location.GPSTracker;
import com.alkandros.linesmash.location.ILocationCallBack;

/**
 * @author Jiju Induchoodan
 *
 */
public class StartPage extends BaseActivity implements OnClickListener,ILocationCallBack{
	
	private Button btnSignin;
	private Button btnGps;
	private Button btnContinue;
	private Intent intent;
	private EditText edtLocation;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_start_page);
		initialiseUI();
		setButtons();
	}
	private void initialiseUI()
	{
		btnContinue   = (Button)findViewById(R.id.btn_continue);
		btnSignin	  = (Button)findViewById(R.id.btn_signin);
		btnGps		  = (Button)findViewById(R.id.btn_gps);
		edtLocation   = (EditText)findViewById(R.id.edt_location);
	}
	private void setButtons()
	{
		btnSignin.setOnClickListener(this);
		btnContinue.setOnClickListener(this);
		btnGps.setOnClickListener(this);

		/*SelectorManager.setBackground(btnSignin, 
				SelectorManager.getButtonDrawableByScreenCathegory(this, R.drawable.red_btn, R.drawable.btn_red_press));*/
		
		/*SelectorManager.setBackground(btnContinue, 
				SelectorManager.getButtonDrawableByScreenCathegory(this, R.drawable.white_btn, R.drawable.white_btn_press));*/
	}
	@Override
	public void onClick(View v) {
		if(v==btnContinue)
		{
			intent = new Intent(this,ActionSelection.class);
			intent.putExtra("signed_in", false);
		}
		else if(v==btnGps)
		{
			if(gps.canGetLocation())
			{
                AppConstants.APP_LATITUDE = gps.getLatitude();
                AppConstants.APP_LONGITUDE = gps.getLongitude();
                edtLocation.setText(gps.getCompleteAddressString(AppConstants.APP_LATITUDE,  AppConstants.APP_LONGITUDE));
            }
			else
			{
                gps.showSettingsAlert();
            }
			return;
		}
		else if(v==btnSignin)
		{
			intent = new Intent(StartPage.this, SignIn.class);
		}
		startActivity(intent);
	}
	
	@Override
	public void setResult(String address) {
		edtLocation.setText(address);
		
	}
}